Skip to content

Conversation

Jack251970
Copy link
Member

@Jack251970 Jack251970 commented May 2, 2025

From #3314. Resolve #2605.

Improve update logic

Improve main view model update logic.

Fix update logic issue

We should not use e.Query.RawQuery != QueryText because QueryText (Input) is different from RawQuery (Query).

Add new property Input for Query

Input is the property without trimming whitespace and it can help developer get the raw input.

Clear results when there are no update tasks

In this function, we need to reset all things because there are no update tasks.

if (ShouldClearExistingResultsForNonQuery(plugins))
{
    // No update tasks and just return
    ClearResults();
    return;
}

Test

  • Input long string fast and interface will update instantly.

@Jack251970 Jack251970 requested review from Copilot and taooceros May 2, 2025 04:44
@Jack251970 Jack251970 requested a review from jjw24 May 2, 2025 04:44
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the update logic in the main view model by refactoring how running and current queries are tracked and by updating the QueryBuilder.Build method signature to accept separate input and trimmed text parameters.

  • Refactored MainViewModel to replace _isQueryRunning with two distinct query state variables.
  • Updated QueryBuilder.Build calls in view model, tests, and main window to pass both raw and trimmed query text.
  • Added documentation for the new Query.Input property and corresponding changes in QueryBuilder.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Flow.Launcher/ViewModel/MainViewModel.cs Refactored query state tracking and updated QueryBuilder.Build invocations.
Flow.Launcher/MainWindow.xaml.cs Updated QueryBuilder.Build call for consistency in query text handling.
Flow.Launcher.Test/QueryBuilderTest.cs Adjusted tests to accommodate the updated QueryBuilder.Build signature.
Flow.Launcher.Plugin/Query.cs Added Input property documentation.
Flow.Launcher.Core/Plugin/QueryBuilder.cs Changed Build method signature to accept both raw input and trimmed text.
Comments suppressed due to low confidence (1)

Flow.Launcher/ViewModel/MainViewModel.cs:372

  • [nitpick] Ensure that passing the untrimmed QueryText as the first parameter while the second parameter is trimmed is the intended behavior, and document this design choice for clarity.
var query = QueryBuilder.Build(QueryText, QueryText.Trim(), PluginManager.NonGlobalPlugins);

This comment has been minimized.

Copy link

gitstream-cm bot commented May 2, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

This comment has been minimized.

Copy link
Contributor

coderabbitai bot commented May 2, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adds an untrimmed input field to Query (Query.Input) and updates QueryBuilder.Build to accept both raw and trimmed input; callsites and tests updated. Refactors MainViewModel internals for query-tracking, cancellation, progress, and result-clearing to track Query instances and use async cancellation.

Changes

Cohort / File(s) Change Summary
Query model & builder
Flow.Launcher.Plugin/Query.cs, Flow.Launcher.Core/Plugin/QueryBuilder.cs
Added public string Input { get; internal init; } to Query. Changed QueryBuilder.Build signature to Build(string input, string text, Dictionary<...>) and populate Query.Input (explicitly sets empty string for empty input).
View and VM callsites
Flow.Launcher/MainWindow.xaml.cs, Flow.Launcher/ViewModel/MainViewModel.cs
Updated callers to pass both raw and trimmed query texts to QueryBuilder.Build. Replaced _isQueryRunning with _progressQuery and _updateQuery; introduced async cancellation via CancelAsync; reworked QueryResultsAsync flow, progress-bar timing, and result-clearing gated by Query identity.
Tests
Flow.Launcher.Test/QueryBuilderTest.cs
Updated QueryBuilder.Build invocations to the three-argument form (raw input, trimmed text, plugins); assertions unchanged.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant User
    participant MainWindow
    participant MainViewModel
    participant QueryBuilder
    participant Plugins

    User->>MainWindow: types rawInput
    MainWindow->>MainViewModel: Submit QueryText (rawInput)
    MainViewModel->>QueryBuilder: Build(rawInput, processedText, plugins)
    Note right of QueryBuilder #DDDDFF: sets Query.Input = rawInput
    QueryBuilder-->>MainViewModel: Query { Input, Search, RawQuery, ... }
    MainViewModel->>MainViewModel: set _progressQuery and _updateQuery
    MainViewModel->>Plugins: run plugin queries (async, cancellable)
    alt query still current
        MainViewModel->>MainWindow: show progress, update results
    else cancelled or replaced
        MainViewModel->>MainWindow: clear/hide results
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • taooceros
  • jjw24

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning In addition to the untrimmed input support from issue #2605, this PR contains extensive internal refactoring of the main view model’s update and cancellation logic, progress tracking adjustments, history gating, and progress bar timing that are unrelated to preserving raw user input. Consider splitting the view model refactor and cancellation logic improvements into a separate pull request or updating the linked issues to explicitly include these broader update logic enhancements to clarify their scope.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues Check ✅ Passed The pull request adds the Input property to the Query class, updates QueryBuilder.Build to accept and assign the raw untrimmed input, and refactors view model and UI code to pass and compare e.Query.Input instead of RawQuery, thereby preserving original whitespace and exposing the untrimmed input in all plugin APIs as specified by issue #2605.
Description Check ✅ Passed The description clearly outlines the enhancements to the view model update logic, the rationale for replacing RawQuery comparisons with the new Input property, the addition of the untrimmed Input field on Query, and the behavior for clearing results when no update tasks remain, directly corresponding to the changes in the code.
Title Check ✅ Passed The title clearly references the primary modifications in the pull request—enhancing and fixing the update logic flow and adding a new Input property to the Query class—so it directly reflects the main changes introduced by the author.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch improve_update

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
Flow.Launcher/ViewModel/MainViewModel.cs (2)

239-265: Redundant guards – can be collapsed for clarity

The same three-part condition (_currentQuery == null || e.Query.RawQuery != _currentQuery.RawQuery || …) is evaluated twice, once before cloning the results and once after.
Keeping a single guard at the top of the handler avoids duplication and a tiny amount of wasted work.

-                    if (_currentQuery == null || e.Query.RawQuery != _currentQuery.RawQuery || e.Token.IsCancellationRequested)
-                    {
-                        return;
-                    }
-
-                    var token = e.Token == default ? _updateSource.Token : e.Token;
-
-                    if (_currentQuery == null || e.Query.RawQuery != _currentQuery.RawQuery || token.IsCancellationRequested)
-                    {
-                        return;
-                    }
+                    var token = e.Token == default ? _updateSource.Token : e.Token;
+                    if (_currentQuery == null ||
+                        e.Query.RawQuery != _currentQuery.RawQuery ||
+                        token.IsCancellationRequested)
+                    {
+                        return;
+                    }

372-373: Minor readability nit – avoid double-trim

QueryText is already passed as the raw input. Calling QueryText.Trim() for the second parameter means the string is trimmed twice inside Build. You can save an allocation by trimming once:

-var query = QueryBuilder.Build(QueryText, QueryText.Trim(), PluginManager.NonGlobalPlugins);
+var trimmed = QueryText.Trim();
+var query = QueryBuilder.Build(QueryText, trimmed, PluginManager.NonGlobalPlugins);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8bb96d7 and 34c3cda.

📒 Files selected for processing (5)
  • Flow.Launcher.Core/Plugin/QueryBuilder.cs (3 hunks)
  • Flow.Launcher.Plugin/Query.cs (1 hunks)
  • Flow.Launcher.Test/QueryBuilderTest.cs (3 hunks)
  • Flow.Launcher/MainWindow.xaml.cs (1 hunks)
  • Flow.Launcher/ViewModel/MainViewModel.cs (9 hunks)
🧰 Additional context used
🧠 Learnings (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)
Learnt from: Yusyuriv
PR: Flow-Launcher/Flow.Launcher#3118
File: Flow.Launcher/ViewModel/MainViewModel.cs:1404-1413
Timestamp: 2024-12-08T21:12:12.060Z
Learning: In the `MainViewModel` class, the `_lastQuery` field is initialized in the constructor and is never null.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (11)
Flow.Launcher.Plugin/Query.cs (1)

10-14: Good addition of the Input property with clear documentation

The new Input property with appropriate XML documentation clearly explains its purpose and usage guidance. The warning about using Search property instead is consistent with the documentation for RawQuery.

Flow.Launcher/MainWindow.xaml.cs (1)

411-411: Updated QueryBuilder.Build call with proper parameters

The call has been correctly updated to pass both the raw query text and the trimmed text as separate parameters, aligning with the updated method signature in QueryBuilder.cs.

Flow.Launcher.Test/QueryBuilderTest.cs (3)

19-19: Test adjusted to use updated QueryBuilder.Build signature

The test call has been properly updated to include the raw input parameter, maintaining test integrity while accommodating the API change.


42-42: Test adjusted to use updated QueryBuilder.Build signature

The test call has been properly updated to include the raw input parameter, maintaining test integrity while accommodating the API change.


54-54: Test adjusted to use updated QueryBuilder.Build signature

The test call has been properly updated to include the raw input parameter, maintaining test integrity while accommodating the API change.

Flow.Launcher.Core/Plugin/QueryBuilder.cs (4)

9-9: Method signature updated to include the raw input parameter

The Build method signature has been enhanced to accept the raw input as a separate parameter, which will be used to populate the new Input property on the Query class.


14-15: Minor formatting change

Small formatting adjustment with no functional impact.


25-26: Additional whitespace added for readability

Small formatting improvement to enhance code readability.

Also applies to: 32-33


42-42: Correctly setting the new Input property

The new Input property is properly populated with the raw input parameter, completing the implementation of this feature.

Flow.Launcher/ViewModel/MainViewModel.cs (2)

1274-1281: Potential visibility race on _runningQuery

_runningQuery is written on the UI thread and later read from a Task.Delay continuation running on a ThreadPool thread.
Although reference assignments are atomic, without volatile/Interlocked there is no publish-happens-before relation; the ThreadPool may observe a stale value.

If correctness depends on the most recent write, consider:

private volatile Query _runningQuery;

or guarding access with a lock/Interlocked.Exchange.

Would you verify if stale reads could surface in practice? If so, I can help prepare a patch.


1396-1397: Verify parameter order matches QueryBuilder.Build signature

Just a sanity check: Build(rawInput, processedText, nonGlobalPlugins) is expected.
Confirm that QueryText (raw) and queryBuilder.ToString().Trim() (processed) are in the correct order to ensure Query.Input holds the unmodified user text.

@Jack251970 Jack251970 changed the title Improve update logic Improve update logic & Fix update logic issue May 2, 2025
@prlabeler prlabeler bot added the bug Something isn't working label May 2, 2025
@Jack251970 Jack251970 added this to the 1.20.0 milestone May 2, 2025

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
Flow.Launcher/ViewModel/MainViewModel.cs (2)

35-36: Improved state tracking with dedicated Query objects

This is a good improvement over using a boolean flag. Tracking queries as objects allows for more precise state management and validation.

The existing suggestion to rename these variables to _progressQuery and _updateQuery to more clearly indicate their purposes is still valid.


1254-1255: ⚠️ Potential issue

Compile-time error: TaskScheduler is not awaitable

await TaskScheduler.Default; will not compile because TaskScheduler does not implement GetAwaiter().

-// Switch to ThreadPool thread
-await TaskScheduler.Default;
+// Switch to ThreadPool thread
+await Task.Yield();  // or `await Task.Run(() => {}, _updateSource.Token);`
🧹 Nitpick comments (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)

260-263: Redundant validation check

This is a duplicate of the check on line 240. While it's valid to verify conditions haven't changed, consider extracting this validation to a helper method to avoid duplication.

-if (_updateQuery == null || e.Query.RawQuery != _updateQuery.RawQuery || token.IsCancellationRequested)
-{
-    return;
-}
+if (IsQueryMismatchOrCancelled(_updateQuery, e.Query, token))
+{
+    return;
+}

// Add this helper method to the class
+private bool IsQueryMismatchOrCancelled(Query currentQuery, Query eventQuery, CancellationToken token)
+{
+    return currentQuery == null || eventQuery.RawQuery != currentQuery.RawQuery || token.IsCancellationRequested;
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 381334f and 1381748.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs (9 hunks)
🧰 Additional context used
🧠 Learnings (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)
Learnt from: Yusyuriv
PR: Flow-Launcher/Flow.Launcher#3118
File: Flow.Launcher/ViewModel/MainViewModel.cs:1404-1413
Timestamp: 2024-12-08T21:12:12.060Z
Learning: In the `MainViewModel` class, the `_lastQuery` field is initialized in the constructor and is never null.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (9)
Flow.Launcher/ViewModel/MainViewModel.cs (9)

240-240: Fixed update logic comparison

This fixes the core issue where the update logic incorrectly compared e.Query.RawQuery with QueryText instead of comparing equivalent objects.


373-373: Updated QueryBuilder.Build call with Input parameter

Correctly updated to pass both raw input and trimmed text to match the updated signature.


1221-1221: Reset query state before processing

Good practice to initialize the query state before starting a new query process.


1241-1246: Early return optimization for changed queries

This is a good optimization to prevent processing outdated queries when user input changes rapidly.


1251-1252: Improved query state tracking

Setting both the progress and update query objects provides better tracking of the query lifecycle.


1291-1302: Progress bar visibility linked to query state

Good implementation of delayed progress bar visibility that also checks if the query is still active before showing it.


1325-1332: Reset progress query after completion

Properly manages the progress state and progress bar visibility after query execution completes.


1334-1338: Added safety with try-finally block

The finally block ensures the query state is cleaned up even if an exception occurs, preventing state leakage.


1414-1414: Updated call to match new QueryBuilder.Build signature

Correctly updated to provide both the original input and the processed query string.

@Jack251970 Jack251970 removed this from the 1.20.0 milestone May 4, 2025
@Jack251970
Copy link
Member Author

Jack251970 commented May 4, 2025

@jjw24 I am not sure if this PR can resolve #3508.

@jjw24
Copy link
Member

jjw24 commented May 4, 2025

Until we can actually figure out what's causing it.

@jjw24 jjw24 added this to the Future milestone May 4, 2025

This comment has been minimized.

Copy link

gitstream-cm bot commented May 5, 2025

🥷 Code experts: theClueless

Jack251970 has most 👩‍💻 activity in the files.
Jack251970, theClueless have most 🧠 knowledge in the files.

See details

Flow.Launcher.Core/Plugin/QueryBuilder.cs

Activity based on git-commit:

Jack251970
MAY 3 additions & 3 deletions
APR
MAR
FEB
JAN
DEC

Knowledge based on git-blame:
theClueless: 53%
Jack251970: 7%

Flow.Launcher.Plugin/Query.cs

Activity based on git-commit:

Jack251970
MAY 4 additions & 3 deletions
APR
MAR
FEB 6 additions & 6 deletions
JAN 1 additions & 13 deletions
DEC

Knowledge based on git-blame:
Jack251970: 11%

Flow.Launcher.Test/QueryBuilderTest.cs

Activity based on git-commit:

Jack251970
MAY
APR
MAR
FEB 20 additions & 19 deletions
JAN
DEC

Knowledge based on git-blame:
theClueless: 57%
Jack251970: 31%

Flow.Launcher/MainWindow.xaml.cs

Activity based on git-commit:

Jack251970
MAY 0 additions & 4 deletions
APR 69 additions & 45 deletions
MAR 1141 additions & 1076 deletions
FEB 1 additions & 1 deletions
JAN
DEC 5 additions & 10 deletions

Knowledge based on git-blame:
Jack251970: 65%

Flow.Launcher/ViewModel/MainViewModel.cs

Activity based on git-commit:

Jack251970
MAY 171 additions & 75 deletions
APR 35 additions & 28 deletions
MAR 695 additions & 628 deletions
FEB 63 additions & 21 deletions
JAN 17 additions & 21 deletions
DEC 59 additions & 63 deletions

Knowledge based on git-blame:
Jack251970: 36%

To learn more about /:\ gitStream - Visit our Docs

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Member

@jjw24 jjw24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I am getting this issue again:
    18 09 PR query
    Logs showed nothing out of the ordinary
    Repro by tying anything really fast, press enter to go to the google search and repeat several times

  2. When restarting flow, it does not start back up again.

Please let me know if you can repro 1 again.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
Flow.Launcher/ViewModel/MainViewModel.cs (3)

286-293: Use the resolved cancellation token in the early guard to avoid wasted work.

If e.Token is default, the current guard won’t respect _updateToken until later, after cloning results.

Apply:

-                    if (_updateQuery == null || e.Query.Input != _updateQuery.Input || e.Token.IsCancellationRequested)
-                    {
-                        return;
-                    }
-
-                    var token = e.Token == default ? _updateToken : e.Token;
+                    var token = e.Token == default ? _updateToken : e.Token;
+                    if (_updateQuery == null || e.Query.Input != _updateQuery.Input || token.IsCancellationRequested)
+                    {
+                        return;
+                    }

441-445: Snapshot QueryText to avoid a tiny race during Backspace.

Take a local copy before Build; prevents edge cases while typing.

-            var query = QueryBuilder.Build(QueryText, QueryText.Trim(), PluginManager.NonGlobalPlugins);
+            var input = QueryText;
+            var query = QueryBuilder.Build(input, input.Trim(), PluginManager.NonGlobalPlugins);

1393-1420: UI-bound property updates from background threads.

After switching to the thread pool, several bindings are set off-UI-thread (PluginIconPath/Source, SearchIconVisibility, ProgressBarVisibility). This risks cross-thread access issues in WPF.

  • Verify no cross-thread exceptions occur; otherwise marshal these sets to the UI dispatcher.

Example for the progress bar continuation:

-                _ = Task.Delay(200, currentCancellationToken).ContinueWith(_ =>
-                {
-                    if (_progressQuery != null && _progressQuery.Input == query.Input)
-                    {
-                        ProgressBarVisibility = Visibility.Visible;
-                    }
-                },
+                _ = Task.Delay(200, currentCancellationToken).ContinueWith(_ =>
+                {
+                    if (_progressQuery != null && _progressQuery.Input == query.Input)
+                    {
+                        Application.Current?.Dispatcher.Invoke(() => {
+                            ProgressBarVisibility = Visibility.Visible;
+                        });
+                    }
+                },
                 currentCancellationToken,
                 TaskContinuationOptions.NotOnCanceled,
                 TaskScheduler.Default);

Apply same pattern (or refactor to a helper) for other UI property sets performed after the thread-pool switch.

Also applies to: 1433-1444, 1491-1499

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6734b9 and f49a86a.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs (9 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-12-08T21:12:12.060Z
Learnt from: Yusyuriv
PR: Flow-Launcher/Flow.Launcher#3118
File: Flow.Launcher/ViewModel/MainViewModel.cs:1404-1413
Timestamp: 2024-12-08T21:12:12.060Z
Learning: In the `MainViewModel` class, the `_lastQuery` field is initialized in the constructor and is never null.

Applied to files:

  • Flow.Launcher/ViewModel/MainViewModel.cs
🧬 Code graph analysis (1)
Flow.Launcher/ViewModel/MainViewModel.cs (3)
Flow.Launcher.Core/Plugin/QueryBuilder.cs (2)
  • Query (9-62)
  • QueryBuilder (7-63)
Flow.Launcher.Plugin/Query.cs (2)
  • Query (8-113)
  • ToString (112-112)
Flow.Launcher.Core/Plugin/PluginManager.cs (5)
  • PluginManager (24-829)
  • PluginManager (166-172)
  • ICollection (313-336)
  • ICollection (338-341)
  • PluginPair (467-470)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (7)
Flow.Launcher/ViewModel/MainViewModel.cs (7)

39-41: Clarify _progressQuery vs _updateQuery roles (naming or doc).

These track similar-but-different states; consider clearer names or brief XML comments to prevent confusion during maintenance.


1368-1369: Good guard with Query.Input vs QueryText.

Prevents stale work when input changes mid-flight.


1450-1456: Nice: proactively clear results when no update tasks (home).

Prevents stale items and aligns with the new non-query clearing logic.


1603-1604: Build with empty input/text for whitespace case is correct.


1623-1624: Good fix: pass method parameter as Input to avoid race.

Matches the new signature and prevents stale-query mismatches.


1936-1939: No change required — projects target .NET 9 so CancelAsync is supported. All csproj TargetFrameworks are net9.0(-windows...), and CancelAsync was introduced in .NET 8, so the CancelAsync calls will compile.


1384-1386: No change required — await TaskScheduler.Default is valid (VS Threading present transitively)

MainViewModel.cs has using Microsoft.VisualStudio.Threading and Flow.Launcher references Flow.Launcher.Infrastructure which contains <PackageReference Include="Microsoft.VisualStudio.Threading" Version="17.14.15" />, so the awaitable extension is available.

@Jack251970
Copy link
Member Author

Jack251970 commented Sep 23, 2025

@jjw24 I failed to reproduce this issue during today's usage and fast typing. But since the first issue you pointed out is related to IResultUpdate, I reverted some of changes, and could you please test if it resolves that issue?

https://ci.appveyor.com/project/JohnTheGr8/flow-launcher/builds/52791393/artifacts

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f49a86a and e01109d.

📒 Files selected for processing (2)
  • Flow.Launcher/MainWindow.xaml.cs (1 hunks)
  • Flow.Launcher/ViewModel/MainViewModel.cs (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher/MainWindow.xaml.cs
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-12-08T21:12:12.060Z
Learnt from: Yusyuriv
PR: Flow-Launcher/Flow.Launcher#3118
File: Flow.Launcher/ViewModel/MainViewModel.cs:1404-1413
Timestamp: 2024-12-08T21:12:12.060Z
Learning: In the `MainViewModel` class, the `_lastQuery` field is initialized in the constructor and is never null.

Applied to files:

  • Flow.Launcher/ViewModel/MainViewModel.cs
🧬 Code graph analysis (1)
Flow.Launcher/ViewModel/MainViewModel.cs (3)
Flow.Launcher.Core/Plugin/QueryBuilder.cs (2)
  • Query (9-62)
  • QueryBuilder (7-63)
Flow.Launcher.Plugin/Query.cs (2)
  • Query (8-113)
  • ToString (112-112)
Flow.Launcher.Core/Plugin/PluginManager.cs (5)
  • PluginManager (23-821)
  • PluginManager (161-167)
  • ICollection (305-328)
  • ICollection (330-333)
  • PluginPair (459-462)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
Flow.Launcher/ViewModel/MainViewModel.cs (6)

39-40: Naming and intent are clear; keep.

The split between progress tracking and update gating reads well. Consider brief XML docs to cement intent for future maintainers.


286-293: Harden ResultsUpdated gating and avoid mixed-token checks.

Use the resolved token for both the cancellation check and keep comparisons ordinal for perf/correctness on raw text.

-                    if (_updateQuery == null || e.Query.Input != _updateQuery.Input || e.Token.IsCancellationRequested)
+                    var token = e.Token == default ? _updateToken : e.Token;
+                    if (token.IsCancellationRequested
+                        || _updateQuery == null
+                        || !string.Equals(e.Query.Input, _updateQuery.Input, StringComparison.Ordinal))
                     {
                         return;
                     }
-
-                    var token = e.Token == default ? _updateToken : e.Token;

1417-1436: Progress-bar trigger: compare with ordinal and consider snapshot.

Use ordinal comparison for raw text; if you adopt the input snapshot above, compare against it for extra safety.

-                    if (_progressQuery != null && _progressQuery.Input == query.Input)
+                    if (_progressQuery != null &&
+                        string.Equals(_progressQuery.Input, query.Input, StringComparison.Ordinal))
                     {
                         ProgressBarVisibility = Visibility.Visible;
                     }

1687-1702: Minor: _lastQuery is never null in ctor; simplify null-propagation.

You can drop the null-conditional on _lastQuery for a tiny clarity bump. Not a blocker.

Based on learnings

-            if (_lastQuery?.ActionKeyword != query?.ActionKeyword)
+            if (_lastQuery.ActionKeyword != query?.ActionKeyword)

1350-1415: Potential cross-thread property updates (minor).

Property assignments (e.g., PluginIconPath, SearchIconVisibility) happen after the thread hop in the current code. With the compile fix above (use Task.Yield), you’ll continue on the UI context and avoid cross-thread UI-binding surprises.


286-323: Use ordinal comparisons consistently for raw text.

All string-equality checks on Input/RawQuery should be StringComparison.Ordinal.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e01109d and 61ee542.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs (8 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-12-08T21:12:12.060Z
Learnt from: Yusyuriv
PR: Flow-Launcher/Flow.Launcher#3118
File: Flow.Launcher/ViewModel/MainViewModel.cs:1404-1413
Timestamp: 2024-12-08T21:12:12.060Z
Learning: In the `MainViewModel` class, the `_lastQuery` field is initialized in the constructor and is never null.

Applied to files:

  • Flow.Launcher/ViewModel/MainViewModel.cs
🧬 Code graph analysis (1)
Flow.Launcher/ViewModel/MainViewModel.cs (3)
Flow.Launcher.Core/Plugin/QueryBuilder.cs (2)
  • Query (9-62)
  • QueryBuilder (7-63)
Flow.Launcher.Plugin/Query.cs (2)
  • Query (8-113)
  • ToString (112-112)
Flow.Launcher.Core/Plugin/PluginManager.cs (3)
  • PluginManager (23-821)
  • PluginManager (161-167)
  • PluginPair (459-462)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: gitStream.cm
🔇 Additional comments (14)
Flow.Launcher/ViewModel/MainViewModel.cs (14)

444-452: Correct: Build now receives both Input (untrimmed) and text (trimmed).

This aligns Backspace with the new QueryBuilder API and preserves user input semantics.


1337-1345: Don’t abort after shortcut expansion (stale guard).

ConstructQueryAsync can rewrite QueryText (builtin/custom shortcuts). Comparing query.Input with the live QueryText right after that will often differ and prematurely return, yielding an empty/stale result pane after expansions.

Apply this to snapshot the input before constructing the query and relax the guard to allow either the original input or the expanded RawQuery:

-            var query = await ConstructQueryAsync(QueryText, Settings.CustomShortcuts, Settings.BuiltinShortcuts);
+            var inputSnapshot = QueryText;
+            var query = await ConstructQueryAsync(inputSnapshot, Settings.CustomShortcuts, Settings.BuiltinShortcuts);
@@
-                // Check if the input text matches the query text
-                if (query.Input != QueryText) return;
+                // Short-circuit only if user has typed something new unrelated to this query
+                var currentText = QueryText;
+                if (!string.Equals(currentText, inputSnapshot, StringComparison.Ordinal) &&
+                    !string.Equals(currentText, query.RawQuery, StringComparison.Ordinal))
+                {
+                    return;
+                }

1485-1499: Result-clearing logic looks correct; good early return when no update tasks.

This prevents stale results when home-page plugins are all disabled or absent.

If you want to be extra sure, test with:

  • ShowHistoryResultsForHomePage = false
  • All home plugins disabled
  • Enter/clear text to confirm the view clears.

1596-1599: Good: Build for whitespace path sets both Input and RawQuery empty.

This keeps IsHomeQuery true and avoids null queries.


1618-1619: Good: pass the method parameter as Input to avoid races.

Using queryText here ensures the built Query carries the exact input used for construction.


217-277: Channel consumer resiliency looks fine; continuation restarts on fault.

No action needed.


571-588: UI navigation helpers unchanged; LGTM.

Selection and preview update wiring remains consistent.

Also applies to: 607-622


1510-1517: ClearResults helper is cohesive and idempotent.

Approach to collapse/clear/reset states is sound.


1523-1572: Per-plugin query path is correct; good use of Task.Yield and cloning.

No issues spotted.


327-338: Clock/date timer ok.

PeriodicTimer loop is simple and cancellation-free as intended.


1951-1958: Dialog focus restore is guarded and logged; ok.

No changes requested.


2276-2303: Dispose pattern correct; writers completed and tasks disposed.

Looks good.


1379-1381: Compile-time error: TaskScheduler is not awaitable.

await TaskScheduler.Default; won’t compile and also risks property updates off the UI thread. Use an awaitable construct; you don’t need to hop threads here since plugin work is already offloaded per-plugin.

-                // Switch to ThreadPool thread
-                await TaskScheduler.Default;
+                // Yield once without changing context (plugin queries run on background tasks)
+                await Task.Yield();

1335-1499: No extra await TaskScheduler.Default or stale-query guards found
Only the await at MainViewModel.cs:1380 and the input guard at 1363 exist.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors and Warnings Count
❌ forbidden-pattern 2
⚠️ non-alpha-in-dictionary 2

See ❌ Event descriptions for more information.

Forbidden patterns 🙅 (1)

In order to address this, you could change the content to not match the forbidden patterns (comments before forbidden patterns may help explain why they're forbidden), add patterns for acceptable instances, or adjust the forbidden patterns themselves.

These forbidden patterns matched content:

s.b. workaround(s)

\bwork[- ]arounds?\b
If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@Jack251970 Jack251970 changed the title Improve update logic & Fix update logic issue & Input for Query Improve update logic & Fix update logic issue & Add Input for Query Sep 29, 2025
@Jack251970 Jack251970 modified the milestones: Future, 2.1.0 Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
10 min review bug Something isn't working enhancement New feature or request review in progress Indicates that a review is in progress for this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: Support Untrimmed query for Flow Launcher's Query
3 participants